﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>ZiDianAdd</title>

    <link href="~/layui-v2.6.8/layui/css/layui.css" rel="stylesheet" />
    <script src="~/layui-v2.6.8/layui/layui.js"></script>
    <script src="~/lib/jquery/dist/jquery.js"></script>

</head>
<body>
    <h1>添加字典数据</h1>


    <form class="layui-form" action="" id="UptForm">

        <div class="layui-form-item">
            <label class="layui-form-label">字典类别</label>
            <div class="layui-input-block">
                <input type="text" name="zid" id="zid" lay-verify="title" autocomplete="off" placeholder="请输入字典类别" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">字典类别</label>
            <div class="layui-input-block">
                <input type="text" name="ztype" id="ztype" lay-verify="title" autocomplete="off" placeholder="请输入字典类别" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">字典值</label>
            <div class="layui-input-block">
                <input type="text" name="zhi" id="zhi" lay-verify="title" autocomplete="off" placeholder="请输入字典值" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">拼音码</label>
            <div class="layui-input-block">
                <input type="text" name="zma" id="zma" lay-verify="title" autocomplete="off" placeholder="请输入拼音码" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">显示顺序</label>
            <div class="layui-input-block">
                <input type="text" name="zshi" id="zshi" lay-verify="title" autocomplete="off" placeholder="请输入显示顺序" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <input type="text" name="zzt" id="zzt" lay-verify="title" autocomplete="off" placeholder="请输入备注" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="text" name="zint" id="zint" lay-verify="title" autocomplete="off" placeholder="请输入状态" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">立即修改</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
    <script>


    $().ready(function () {//文档就绪函数
        $.ajax({//反填AJAX(用ViewBag传值)
            url:'http://localhost:36862/api/JuSe/ZDFan?id='+@ViewBag.id,//调API字典控制器里翻天的方法
            success: function (d) {//回调函数
                $("#zid").val(@ViewBag.id)

                $("#ztype").val(d.data.ztype)
                $("#zhi").val(d.data.zhi)
                $("#zma").val(d.data.zma)
                $("#zshi").val(d.data.zshi)
                $("#zzt").val(d.data.zzt)
                $("#zint").val(d.data.zint)
            }
        })
    })
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });
        //创建一个编辑器
        var editIndex = layedit.build('LAY_demo_editor');
        //监听指定开关
        form.on('switch(switchTest)', function (data) {
            layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
        });

        //监听提交
        form.on('submit(demo1)', function (data) {
            $.ajax({//修改的AJAX
                url: 'http://localhost:36862/api/JuSe/ZDUpt',
                data: $("#UptForm").serialize(),
                type: 'post',
                success: function (d) {
                    if (d > 0) {
                        layer.msg('修改成功!', { time: 2000, icon: 1 }, function () {
                            parent.location.href = '/ZiDian/ZiDianShow';
                        })
                    }
                    else {
                        layer.msg('修改失败!', { time: 2000, icon: 2 }, function () {
                            parent.location.href = '/ZiDian/ZiDianShow';
                        })
                    }
                }
            })
            return false;
        });
        //表单赋值
        layui.$('#LAY-component-form-setval').on('click', function () {
            form.val('example', {
                "username": "贤心" // "name": "value"
                , "password": "123456"
                , "interest": 1
                , "like[write]": true //复选框选中状态
                , "close": true //开关状态
                , "sex": "女"
                , "desc": "我爱 layui"
            });
        });

        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function () {
            var data = form.val('example');
            alert(JSON.stringify(data));
        });
    });
    </script>
</body>
</html>

